package com.clms.maintain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.clms.maintain.mapper.ShopMapper;
import com.clms.maintain.pojo.entity.TbRecord;
import com.clms.maintain.pojo.entity.TbShop;
import com.clms.maintain.pojo.vo.ShopVo;
import com.clms.maintain.service.ShopService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-third
 * @description: 维修厂的逻辑层
 * @author: 许鹏
 * @create: 2021-07-23 10:00
 **/
@Component
@ApiModel(value = "maintain实现类",description = "维修厂的实现类")
public class ShopServiceImpl implements ShopService {

    @Resource
    private ShopMapper shopMapper;

    @Override
    @ApiModelProperty(value ="维修厂的分页查询")
    public R selectShopAll(Integer currentPage, Integer pageSize, ShopVo maintainShopVo) {
        Page<TbShop> page = new Page(currentPage,pageSize);
        QueryWrapper<TbRecord> wrapper = new QueryWrapper<>();


        IPage<TbShop> data = shopMapper.selectPage(page,null );
        return R.ok().put("total",data.getTotal()).put("records",data.getRecords());
    }

    @Override
    @ApiModelProperty(value = "添加维修")
    public R insertShop(TbShop tbShop) {
        int i = shopMapper.insert(tbShop);
        if (i>0){
            return R.ok().message("新增成功");
        }
        return R.error().message("新增失败");
    }

    @Override
    @ApiModelProperty(value = "修改维修厂")
    public R updateShop(TbShop tbShop) {
        int i = shopMapper.updateById(tbShop);
        if (i>0){
            return R.ok().message("修改成功");
        }
        return R.ok().message("修改失败");
    }

    @Override
    @ApiModelProperty(value = "通过id查询维修厂")
    public R selectById(Integer id) {
        TbShop tbShop = shopMapper.selectById(id);
        return R.ok().put("tbshop",tbShop);
    }

    @Override
    @ApiModelProperty(value = "通过id删除修车厂")
    public R deleteShop(Integer id) {
        int i = shopMapper.deleteById(id);
        if (i>0){
            return R.ok().message("删除成功");
        }
        return R.error().message("删除失败");
    }

    @Override
    public R selectAllList() {
        List<TbShop> tbShops = shopMapper.selectList(null);
        return R.ok().put("tbShops",tbShops);
    }
}
